-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[nodejs] add bun backend #101
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you fill in details in the PR please?
bun can be used to replace a nodejs packager, but it can also be used in its own runtime. As such, it's not accurate to label it as a 'nodejs' backend
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! I am excited.
Specfile: "package.json", | ||
Lockfile: "bun.lockb", | ||
FilenamePatterns: nodejsPatterns, | ||
Quirks: api.QuirksAddRemoveAlsoLocks | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
additional env vars that might be helpful:
BUN_CONFIG_SKIP_SAVE_LOCKFILE
BUN_CONFIG_SKIP_LOAD_LOCKFILE
BUN_CONFIG_SKIP_INSTALL_PACKAGES
BUN_INSTALL_VERBOSE
GOMAXPROCS
(control max number of threads used, not in go but didn't want to make up a new env var for this)BUN_MANIFEST_CACHE=0
: no cacheBUN_MANIFEST_CACHE=1
: read the cache, but ignore Cache-Control headersBUN_MANIFEST_CACHE=2
: read the cache & follow Cache-Control headers (default)BUN_INSTALL_CACHE_DIR
BUN_INSTALL
(directory bun was installed in, not bun install)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is more config in bunfig.toml
: https://github.com/oven-sh/bun/blob/jarred/new-bundler/src/bunfig.zig#L235-L426
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
due to hoisting, will often contain duplicate versions
That's fine, right now UPM only accepts one version per package, which is problematic anyways. The package version that's last in the output will be the one that's reported by UPM
So there seems to be 2 ways of reading the packages and versions in the bun lockfile:
- executing the
bun.lockb
file- this is what's done by UPM in this PR
- is there a way to ensure that the output format is yarn's from the command line, ie without relying on the
bunfig.toml
file?
- via
bun pm ls --all
- I can probably switch to this, and that would be preferred in my opinion
- is the output format considered stable? ie, if I write a regex for reading the package name and version eg
(@[a-z]+\/)?[a-z]+@[0-9]+\.[0-9]+\.[0-9]+
is there any possibility that the regex will break in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
those env vars are definitely helpful for some other things we have planned with bun, thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bun pm hash-string
might be easier for parsing and we cannot change it because doing so would invalidate lockfiles unexpectedly (we use that to determine if we should bother saving the lockfile)
❯ bun pm hash-string
-- BEGIN SHA512/256(`${alphabetize(name)}@${order(version)}`) --
@eslint/[email protected]
@humanwhocodes/[email protected]
@humanwhocodes/[email protected]
@humanwhocodes/[email protected]
@nodelib/[email protected]
@nodelib/[email protected]
@nodelib/[email protected]
@types/[email protected]
@types/[email protected]
@types/[email protected]
@types/[email protected]
@types/[email protected]
@typescript-eslint/[email protected]
@typescript-eslint/[email protected]
@typescript-eslint/[email protected]
@typescript-eslint/[email protected]
@typescript-eslint/[email protected]
@typescript-eslint/[email protected]
@typescript-eslint/[email protected]
@typescript-eslint/[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
bun-webkit-linux-amd64@0.0.1-595dd33692e02001631f6c3ab6f2bbb199278d26
bun-webkit-linux-arm64@0.0.1-595dd33692e02001631f6c3ab6f2bbb199278d26
bun-webkit-macos-amd64@0.0.1-595dd33692e02001631f6c3ab6f2bbb199278d26
bun-webkit-macos-arm64@0.0.1-595dd33692e02001631f6c3ab6f2bbb199278d26
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
-- END HASH--
We probably should just add a way to print this info as JSON though.
Also you should set COLORTERM=0
to ensure ansi color codes don't get included in output. It should be smart enough to detect this, but good to proactively disable that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though bun pm hash-string
returns all packages in the lockfile, but not all these packages will ultimately install (bun-webkit-linux-arm64
, for example, is not installed on linux x64 but exists in the lockfile so that the lockfile is consistent across operating systems and CPU architectures)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, it could be a future feature for UPM to detect platform-specific dependencies and filter/collate them, but that's not a large concern at the moment. Seems bun pm hash-string
is the best option here - thanks!
latest change using
|
internal/backends/nodejs/nodejs.go
Outdated
// - 1.2.3 | ||
// - 1.2.3-beta.1 | ||
// - 1.2.3-beta.1-build.1 | ||
r := regexp.MustCompile(`(?m)^(@?[^@ \n]+)@([0-9]+\.[0-9]+\.[0-9]+(-.+)?)$`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, good catch - should be fixed in latest commit. thanks!
We'd like to have better support for bun and encourage its usage in JS projects. This adds a new backend to UPM for
bun
, added as thebun
language ieupm --language bun
.Note that the bun lockfile format is in a binary format that's only recognizable by bun, but it's also executable, resulting in a yarn lockfile format being printed to stdout. As such, for reading the lockfile, this backend executes the lockfile with
bun
and then operates on the resulting output.